#include <bits/stdc++.h>
int main (){int T,n,m;scanf("%d",&T);while(T--){scanf("%d %d",&n,&m);printf("%d\n",((n-n/m-(n%m!=0))&1)^1);}}
